package com.metis.document.parse.dialog.pipeline.impl;

import com.metis.document.parse.dialog.pipeline.TextFilter;
import com.metis.document.parse.dialog.pipeline.TitleTextFilter;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;

import java.util.regex.Pattern;

/**
 * 前言过滤器
 */
@Component
@Slf4j
public class PrefaceFilter implements TitleTextFilter, TextFilter {
    private static final Pattern pattern = Pattern.compile("(?:前[\\s]*言)");

    @Override
    public boolean needToFilter(@NotNull String input) {
        if (pattern.matcher(input.replaceAll("[\\p{Z}\\s]+", "")).find()) {
            log.info("匹配到前言，{}", input);
            return true;
        }
        return false;
    }
}
